package com.learning.db.optimization;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;


/**
 * 订单表：
 *
 * @author hyc
 */
@Setter
@Getter
@EqualsAndHashCode
public class DBYB_dataBean implements WritableComparable<DBYB_dataBean> {

    private String PersonId;
    private String MedicalId;
    private String SOwnExpense;
    private String sum_OwnExpense;
    private String money;
    private String sum_POwnExpense;
    private String Compliance;
    private String sum_Compliance;
    private String sum_OwnExpense_add_sum_Compliance;
    private String money2;
    private String sum_POwnExpense_add_Compliance;
    private String SettlementDate;
    private String systemdate;
    // flag=1表示是否是往期数据
    private String flag;
    private String OwnExpense_add_Compliance;
    private String SlaveFlag;

    /*    public void set(String PersonId, String MedicalId, String SOwnExpense, String sum_OwnExpense, String money,
                        String sum_POwnExpense, String Compliance, String sum_Compliance ,String sum_OwnExpense_add_sum_Compliance ,
                        String money2 , String sum_POwnExpense_add_Compliance, long SettlementDate,String systemdate, String flag) {
            this.PersonId = PersonId;
            this.MedicalId = MedicalId;
            this.SOwnExpense = SOwnExpense;
            this.sum_OwnExpense = sum_OwnExpense;
            this.money = money;
            this.sum_POwnExpense = sum_POwnExpense;
            this.Compliance = Compliance;
            this.sum_Compliance = sum_Compliance;
            this.sum_OwnExpense_add_sum_Compliance = sum_OwnExpense_add_sum_Compliance;
            this.money2 = money2;
            this.sum_POwnExpense_add_Compliance = sum_POwnExpense_add_Compliance;
            this.SettlementDate = SettlementDate;
            this.systemdate = systemdate;
            this.flag = flag;
        }*/
    @Override
    public void readFields(DataInput in) throws IOException {

        this.PersonId = in.readUTF();
        this.MedicalId = in.readUTF();
        this.SOwnExpense = in.readUTF();
        this.Compliance = in.readUTF();
        this.OwnExpense_add_Compliance = in.readUTF();
        this.SlaveFlag = in.readUTF();
        this.SettlementDate = in.readUTF();
        this.flag = in.readUTF();
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeUTF(PersonId);
        out.writeUTF(MedicalId);
        out.writeUTF(SOwnExpense);
        out.writeUTF(Compliance);
        out.writeUTF(OwnExpense_add_Compliance);
        out.writeUTF(SlaveFlag);
        out.writeUTF(SettlementDate);
        out.writeUTF(flag);
    }

    @Override
    public String toString() {
        /**
         1.人员编号|2.医疗结算事件id|3.自负金额|4.累计自负费用|5.本次自负赔付|6.累计自负赔付|7.取小后的本次合规自费费用
         |8.累计合规费用|9.累计自负费用+累计合规费用|10.本次自负加合规赔付|11.累计自负加合规赔付|结算日期|当前日期时间
         */
        return String.format("%-20s", PersonId) + "|" + String.format("%-20s", MedicalId) + "|" + String.format("%-20s", SOwnExpense) + "|" + String.format("%-20s", sum_OwnExpense) + "|"
                + String.format("%-20s", money) + "|" + String.format("%-20s", sum_POwnExpense) + "|" + String.format("%-20s", Compliance) + "|" + String.format("%-20s", sum_Compliance) + "|" + String.format("%-20s", sum_OwnExpense_add_sum_Compliance) +
                "|" + String.format("%-20s", money2) + "|" + String.format("%-20s", sum_POwnExpense_add_Compliance) + "|" + String.format("%-20s", SettlementDate) + "|" + String.format("%-20s", systemdate);

    }


    @Override
    public int compareTo(DBYB_dataBean o) {
        int compare = this.PersonId.compareToIgnoreCase(o.getPersonId());
        if (compare == 0) {
            return this.SettlementDate.compareTo(o.getSettlementDate());
        } else {
            return compare;
        }
//        return compare == 0 ? (Long.compare(SettlementDate, o.getSettlementDate()) == 0 ? MedicalId.compareTo(o.getMedicalId()) : Long.compare(SettlementDate, o.getSettlementDate())) : compare;
    }

    /**
     * 约定顺序的读取数据
     *
     * @param arr
     */
    public void loadDate(String[] arr) {
        this.PersonId = arr[0];
        this.MedicalId = arr[1];
        this.SOwnExpense = arr[2];
        this.Compliance = arr[7];
        this.OwnExpense_add_Compliance = arr[8];
        this.SlaveFlag = arr[9];
        this.SettlementDate = arr[10];
    }
}